package com.tarena.security.admin.persistis.repository;


import com.tarena.security.admin.dao.StrategyMapper;
import com.tarena.security.admin.dao.UserRoleMapper;
import com.tarena.security.admin.entity.db.Strategy;
import com.tarena.security.admin.entity.db.UserRole;
import com.tarena.security.admin.exception.SecurityAdminBusinessException;
import com.tarena.security.admin.param.StrategyParam;
import com.tarena.security.admin.persists.repository.StrategyRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import static com.tarena.security.admin.errorenum.ResultEnum.SYSTEM_ERROR;

/**
 * <p>
 * 策略表格 Mapper 接口
 * </p>
 *
 * @author Ly
 * @since 2023-04-10
 */
@Repository
@Slf4j
public class StrategyRepositoryImpl implements StrategyRepository {

    @Autowired
    StrategyMapper strategyMapper;

    //    //插入用户角色信息
//    int insertOne (UserRole userRole);
    @Override
    public int insertOne(Strategy strategy) {
        Integer num = strategyMapper.insertOne(strategy);
        if (num<1) {
            throw new SecurityAdminBusinessException(SYSTEM_ERROR);
        }
        return num;
    }

    @Override
    public Strategy selectOne(Integer Id) {
        Strategy strategy= strategyMapper.selectOne(Id);
        log.info("userRole,{}",strategy);
        if (strategy==null){
            throw new SecurityAdminBusinessException(SYSTEM_ERROR);
        }
        return strategy;
    }

    @Override
    public int deteleOneById(Integer Id) {
        int num = strategyMapper.deleteOneById(Id);
        log.info("num:{}",num);
        if (num<1) {
            throw new SecurityAdminBusinessException(SYSTEM_ERROR);
        }
        return num;
    }

    @Override
    public int updateByStrategy(Strategy strategy) {
        Integer num = strategyMapper.updateByStrategy(strategy);
        if (num<1) {
            throw new SecurityAdminBusinessException(SYSTEM_ERROR);
        }
        return num;
    }
}
